﻿using System;
using System.Windows;
using System.Windows.Controls;
using Silverlight.InputCtrl;
using System.Windows.Resources;
using System.IO;
using CommonExtension;

namespace AttachedbehaviorDemo
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            LblXaml.Text = ReadResourceFile("MainPage.xaml");
            LblCode.Text = ReadResourceFile("AttachedbehaviorDemo.Code");
            ScrllXaml.SetIsMouseWheelScrollingEnabled(true);
            ScrllCode.SetIsMouseWheelScrollingEnabled(true);
        }

        private string ReadResourceFile(string FileName)
        {
            StreamResourceInfo sri = Application.GetResourceStream(
                new Uri(this.GetType().Namespace + ";component/" + FileName, UriKind.Relative));
            string res = null;
            if (sri != null)
            {
                using (StreamReader sr = new StreamReader(sri.Stream, System.Text.Encoding.UTF8))
                {
                    res = sr.ReadToEnd();
                }
            }
            return res;
        }

        private void BntSelectAll_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (TabCode.SelectedIndex == 0)
            {
                LblXaml.Focus();
                LblXaml.Select(0, LblXaml.Text.Length);
            }
            else
            {
                LblCode.Focus();
                LblCode.Select(0, LblCode.Text.Length);
            }
        }

        private void BntVldAll_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            ValidatorManager.ValidateAll();
        }

        private void BntResetAll_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            ValidatorManager.ResetAllValidators();
        }
    }
}
